package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbFreightTemplateMapper;
import com.bw1806.pojo.TbFreightTemplate;
import com.bw1806.pojo.TbFreightTemplateExample;
import com.bw1806.sellergoods.service.TbFreightTemplateService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbFreightTemplateServiceImpl implements TbFreightTemplateService {

    @Autowired
    private TbFreightTemplateMapper tbFreightTemplateMapper;

    @Override
    public List<TbFreightTemplate> findAll() {
        return tbFreightTemplateMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbFreightTemplate> pagelist(TbFreightTemplate tbFreightTemplate,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbFreightTemplateExample example=new TbFreightTemplateExample();

        TbFreightTemplateExample.Criteria criteria = example.createCriteria();

        if(tbFreightTemplate!=null){
            //if(tbFreightTemplate.getName()!=null && tbFreightTemplate.getName().length()>0){
            //    criteria.andNameLike("%"+tbFreightTemplate.getName()+"%");
           // }
        }

        Page<TbFreightTemplate> page= (Page<TbFreightTemplate>) tbFreightTemplateMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbFreightTemplate tbFreightTemplate) {
        Long id = tbFreightTemplate.getId();
        if(id != null && id !=0){
            tbFreightTemplateMapper.updateByPrimaryKey(tbFreightTemplate);
        } else{
            tbFreightTemplateMapper.insert(tbFreightTemplate);
        }
    }

    @Override
    public TbFreightTemplate getById(Long id) {
        return tbFreightTemplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbFreightTemplateMapper.deleteByPrimaryKey(id);
        }
        //tbFreightTemplateMapper.deletebth(ids);
    }
}
